package com.jason.cloud.engine.share.driver.order.service;

import com.jason.cloud.engine.share.driver.order.bean.OrderBean;
import com.jason.cloud.engine.share.driver.order.dao.OrderDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);

    @Resource
    private OrderDao orderDao;

    /**
     * 根据ID变更订单
     * @param id
     * @return
     */
    public OrderBean queryOrderById(String id) {
        OrderBean orderBean = null;
        try {
            orderBean = this.orderDao.queryOrderById(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return orderBean;
    }

    /**
     * 创建变更资费订单
     * @param orderBean
     */
    public void insertOrder(OrderBean orderBean) {
        try {
            this.orderDao.insertOrder(orderBean);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 列举出所有的订单
     * @return
     */
    public List<OrderBean> getOrderByLimit(int page, int size) {
        List<OrderBean> orderBean = new ArrayList<OrderBean>();
        try {
            orderBean = this.orderDao.getOrderByLimit(page, size);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return orderBean;
    }

    /**
     * 计数订单
     * @return
     */
    public int getOrderCount() {
        int count = 0;
        try {
            count = this.orderDao.getOrderCount();
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return count;
    }

    /**
     * 更新订单
     * @param orderBean
     */
    public void updateOrderStatusByOrderId(OrderBean orderBean) {
        try {
            this.orderDao.updateOrderStatusByOrderId(orderBean);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }
}
